package com.whz.crypt.config;

import com.whz.crypt.advice.DecryptRequestBodyAdvice;
import com.whz.crypt.advice.EncryptResponseBodyAdvice;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

/**
 * @author whz
 */
@Configuration
@EnableConfigurationProperties(CryptProperty.class)
@ConditionalOnProperty(name = CryptProperty.PREFIX + ".enable", havingValue = "true")
public class HttpRsaTransportConfiguration {

    @Bean
    public DecryptRequestBodyAdvice tongyuRsaDecryptRequestBodyAdvice(CryptProperty cryptProperty,
                                                                      Environment environment) {
        return new DecryptRequestBodyAdvice(cryptProperty, environment);
    }

    @Bean
    public EncryptResponseBodyAdvice tongyuRsaEncryptResponseBodyAdvice(CryptProperty cryptProperty,
                                                                        Environment environment) {
        return new EncryptResponseBodyAdvice(cryptProperty, environment);
    }
}